const jwt = require('jsonwebtoken')

module.exports = () => {
    return async (ctx, next) => {
        // 获取请求头信息

        const { authorization } = ctx.request.headers

        // 判断token是否存在 存在表示已经登录
        if (authorization) {
            jwt.verify(authorization, '1908A')

            await next()
        } else {
            ctx.body = {
                code: 0,
                msg: "您还未登录，请先登录"
            }
        }
    }
}